package com.jz.community.moduleshopping.timeLimit.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.glideConfig.GlideApp;
import com.jz.community.basecomm.utils.CharacterUtils;
import com.jz.community.basecomm.utils.ConverterUtils;
import com.jz.community.basecomm.utils.RxDataTool;
import com.jz.community.basecomm.utils.RxTextTool;
import com.jz.community.basecomm.utils.RxTimeTool;
import com.jz.community.moduleshopping.R;
import com.jz.community.moduleshopping.timeLimit.bean.LimitGoodsBean;

import java.util.List;

public class LimitGoodsAdapter extends BaseQuickAdapter<LimitGoodsBean.EmbeddedBeanXX.ContentBeanX, BaseViewHolder> {

    public LimitGoodsAdapter(int layoutResId, @Nullable List<LimitGoodsBean.EmbeddedBeanXX.ContentBeanX> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, LimitGoodsBean.EmbeddedBeanXX.ContentBeanX entity) {
        String status = entity.getStatus();
        TextView bt = helper.getView(R.id.tx_flash_bt);
        TextView tv_price = helper.getView(R.id.tx_flash_price);
        TextView tv_active_price = helper.getView(R.id.tx_flash_price_active);
        ImageView imageView = helper.getView(R.id.tx_flash_iv);

        if ("1".equals(status)) {
            //未开抢
            bt.setBackgroundResource(R.drawable.button_border_home);
            bt.setTextColor(mContext.getResources().getColor(R.color.white));
            bt.setText("开抢提醒");
        } else if ("2".equals(status)) {
            //开抢中
            bt.setBackgroundResource(R.drawable.button_border_home);
            bt.setTextColor(mContext.getResources().getColor(R.color.white));
            bt.setText("马上抢");
        } else if ("3".equals(status)) {
            //已结束
            bt.setBackgroundResource(R.drawable.button_border_home_gray);
            bt.setTextColor(mContext.getResources().getColor(R.color.font_black));
            bt.setText("已结束");
        }

        GlideApp.with(mContext)
                .load(entity.getIcon())
                .placeholder(R.mipmap.image_default)
                .error(R.mipmap.image_default)
                .into(imageView);

        helper.setText(R.id.tx_flash_name, entity.getTitle());
        helper.setText(R.id.tx_flash_description, entity.getOutline());
        helper.setText(R.id.tx_flash_person, entity.getSaleCount() + "邻居已购买");

        String activePrice = entity.getSkuInfos().get(0).getDiscountPrice();
        String price = entity.getSkuInfos().get(0).getPrice();
        if (!RxDataTool.isNullString(activePrice)) {
            tv_active_price.setText("¥" + CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(activePrice)));

            tv_price.setVisibility(View.VISIBLE);
            RxTextTool.getBuilder("")
                    .append("¥" + CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(price)))
                    .setStrikethrough()
                    .into(tv_price);
        } else {
            tv_active_price.setText("¥" + CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(price)));
            tv_price.setVisibility(View.GONE);
        }
        helper.addOnClickListener(R.id.tx_flash_bt);
    }

}
